package com.example.daxiguaforharmony.game.core.renderers;

import com.example.daxiguaforharmony.game.core.base.DisplayObject;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Rect;

public class Label extends DisplayObject {

    public String text = null;
    public int textSize = 20;
    public Color textColor = Color.WHITE;

    public Label() {

    }

    @Override
    public void render(Canvas canvas, Paint paint) {
        if (this.text == null || this.text.length() <= 0) return;
        paint.setTextSize(this.textSize);
        paint.setFakeBoldText(true);
        paint.setColor(this.textColor);
        paint.setAlpha(this.alpha);
        Rect rect = paint.getTextBounds(this.text);
        this.width = rect.getWidth();
        this.height = rect.getHeight();
        float px = this.x - (this.width * this.scaleX) / 2f;
        float py = this.y + this.textSize * 0.3f; // - (this.height * this.scaleY) / 2f;
        canvas.drawText(paint, this.text, px, py);
    }

    @Override
    public void destory() {

    }
}
